package cn.edu.neusoft.demo.hospital2.Dao;

import cn.edu.neusoft.demo.hospital2.pojo.Room;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface RoomDao extends BaseMapper<Room> {
    @Results(value = {
            @Result(id = true, property = "roomId", column = "room_id"),
            @Result(property = "roomName", column = "room_name"),
            @Result(property = "departId1", column = "depart_id1"),
            @Result(property = "departId2", column = "depart_id2"),
            @Result(property = "floor", column = "floor")
    })
    @Select("select * from room")
    List<Room> selectList();

    @Insert("insert into room(room_name, depart_id1, depart_id2, floor) values(#{roomName}, #{departId1}, #{departId2}, #{floor})")
    int insert(Room room);

    @Select("select * from room where room_id = #{roomId}")
    Room selectById(Integer roomId);

    @Update("update room set room_name = #{roomName}, depart_id1 = #{departId1}, depart_id2 = #{departId2}, floor = #{floor} where room_id = #{roomId}")
    int updateById(Room room);

    @Delete("delete from room where room_id = #{roomId}")
    int deleteById(Integer roomId);

    @Select("SELECT r.*, d.department_name AS mainDepartmentName " +
            "FROM room r " +
            "LEFT JOIN department d ON r.depart_id1 = d.department_id " +
            "WHERE r.depart_id1 = #{deptId} OR r.depart_id2 = #{deptId}")
    List<Room> selectRoomsByDepartmentId(@Param("deptId") Integer deptId);
}
